<template>
  <div class="home-container">
    <el-container>
      <el-header>
        <div class="logo-img">
          <img src="../assets/heima.png" alt="" />
          <span>电商后台管理系统 </span>
        </div>
        <el-button @click="btn" type="info" size="mini">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="collapse ? '64px' : '200px'">
          <div class="box" @click="btnbox">|||</div>
          <el-menu
            :collapse-transition="false"
            :collapse="collapse"
            :router="true"
            unique-opened
            :default-active="defaultobj"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#409EFF"
          >
            <el-submenu :index="index + ''" v-for="(item, index) in menList" :key="index">
              <template slot="title">
                <i :class="['iconfont', iconobj[index]]" style="margin-right: 10px"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item-group>
                <el-menu-item @click="btnclass(item2.path)" :index="item2.path" v-for="(item2, index2) in item.children" :key="index2"> <i class="el-icon-menu"></i>{{ item2.authName }}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
          <wangEditor />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
import { menus_api } from '@/api'
export default {
  components: {
    wangEditor: () => import('@/views/wangEditor'),
  },
  data() {
    return {
      menList: [],
      iconobj: {
        0: 'icon-user',
        1: 'icon-tijikongjian',
        2: 'icon-shangpin',
        3: 'icon-danju',
        4: 'icon-baobiao',
      },
      defaultobj: window.localStorage.getItem('defaPath') || 'users',
      collapse: false,
    }
  },
  methods: {
    btn() {
      //点击退出到登录页面
      this.$router.push('/login')
      window.sessionStorage.setItem('token', '')
    },
    btnclass(path) {
      console.log(path)

      window.localStorage.setItem('defaPath', path)
      this.defaultobj = path
    },

    //  获取左侧菜单函数
    async getMenus() {
      // const res = await menus_api();
      // console.log(res, 66666);
      // this.menList = res.data.data;
      // const { data: res1 } = await menus_api()

      const { data: res1 } = await menus_api()

      console.log(res1, 555)
      this.menList = res1.data
    },
    btnbox() {
      this.collapse = !this.collapse
    },
  },
  // created() {
  mounted() {
    this.getMenus()
  },
}
</script>
<style scoped lang="less">
.home-container {
  width: 100%;
  height: 100%;
  > .el-container {
    width: 100%;
    height: 100%;
    .el-header {
      display: flex;
      justify-content: space-between;
      padding-left: 0;
      background-color: #373d41;
      .logo-img {
        display: flex;
        align-items: center;

        span {
          color: #fff;
          font-size: 20px;
          margin-left: 20px;
        }
      }

      .el-button {
        height: 40px;
        margin: 10px 0;
        font-size: 15px;
      }
    }
    .el-container {
      flex: 1;
      .el-aside {
        .box {
          background-color: #4a5064;
          font-size: 10px;
          line-height: 24px;
          color: #fff;
          text-align: center;
          letter-spacing: 0.2em;
          cursor: pointer;
        }
        background-color: #333744;
        .el-menu {
          border: none;
        }
      }

      .el-main {
        background-color: #eaedf1;
      }
    }
  }
}
</style>
